﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace IndexMarkSilverlightClient.Classes
{
    public static class DataGridExtensions
    {
        /// <summary>
        /// Gets the list of DataGridRow objects.
        /// </summary>
        /// <param name="grid">The grid wirhrows.</param>
        /// <returns>List of rows of the grid.</returns>
        public static ICollection<DataGridRow> GetRows(this DataGrid grid)
        {
            List<DataGridRow> rows = new List<DataGridRow>();

            foreach (var rowItem in grid.ItemsSource)
            {
                grid.ScrollIntoView(rowItem, grid.Columns[0]);
                FrameworkElement el = grid.Columns[0].GetCellContent(rowItem);
                DataGridRow row = DataGridRow.GetRowContainingElement(el.Parent as FrameworkElement);
                
                if (row != null) rows.Add(row);
            }

            return rows;
        }
    } 
}
